package football.haha.com.footballtv.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.TextUtils;

/**
 * Created by haha on 2017/5/28.
 */

public class ShareTools { 
    // SharedPreferences-------------------------------------------------------start
    public static String getStringPreference(Context context, String tag) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        return sp.getString(tag, "");
    }

    public static void setStringPreference(Context context, String tag, String value) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(tag, value);
        editor.commit();
    }

    public static int getIntegerPreference(Context context, String tag) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        String phoneTag = tag;
        return sp.getInt(phoneTag, 0);
    }

    public static int getIntegerPreference(Context context, String tag, int defaultInt) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        return sp.getInt(tag, defaultInt);
    }


    public static void setIntegerPreference(Context context, String tag, int value) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = sp.edit();
        String phoneTag = tag;
        editor.putInt(phoneTag, value);
        editor.commit();
    }

    public static Long getLongPreference(Context context, String tag) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        return sp.getLong(tag, 0);
    }

    public static void setLongPreference(Context context, String tag, long value) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = sp.edit();
        editor.putLong(tag, value);
        editor.commit();
    }

    public static boolean getBooleanPreference(Context context, String tag) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        if (TextUtils.equals("hadLaunch", tag)){
            return sp.getBoolean(tag, false);
        }else{
            return sp.getBoolean(tag, false);
        }
    }

    public static void setBooleanPreference(Context context, String tag, boolean value) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = sp.edit();
        if (TextUtils.equals("hadLaunch", tag)) {
            editor.putBoolean(tag, value);
        }else{
            editor.putBoolean(tag, value);
        }
        editor.commit();
    }

    public static void setFloatPreference(Context context, String tag, float value) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = sp.edit();
        editor.putFloat(tag, value);
        editor.commit();
    }

    public static float getFloatPreference(Context context, String tag) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        return sp.getFloat(tag, 0.0f);
    }

    // SharedPreferences-------------------------------------------------------end

}
